package com.insurance.controller;

import com.insurance.domain.ResponseResult;
import com.insurance.domain.entity.Customer;
import com.insurance.domain.entity.Product;
import com.insurance.domain.enums.AppHttpCodeEnum;
import com.insurance.domain.vo.CustomerPageVo;
import com.insurance.domain.vo.ProductPageVo;
import com.insurance.service.CustomerService;
import com.insurance.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author qcjstudy
 * @create 2023-04-22 11:25
 */
@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    private ProductPageVo productPageVo;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody ProductPageVo productPageVo){
        this.productPageVo = productPageVo;
        return productService.listByPage(productPageVo);
    }

    @PostMapping()
    public ResponseResult add(@RequestBody Product product){
        return productService.addProduct(product);
    }

    @PutMapping("/update")
    public ResponseResult update(@RequestBody Product product){
        return productService.updateProduct(product);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        if(productService.removeById(id)){
            return ResponseResult.okResult();
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.DELETE_FAILED);
    }
}
